package com.elitel.frame.base.service.jdpPortal.impl;

import com.elitel.frame.base.service.jdpPortal.JdpPortalService;
import com.elitel.frame.main.dao.JdpPortalMapper;
import com.elitel.frame.main.entity.protal.JdpPortal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * @author Lenovo
 * @description 针对表【jdp_portal(平台门户)】的数据库操作Service实现
 * @createDate 2024-10-16 13:12:20
 */
@Service
public class JdpPortalServiceImpl implements JdpPortalService {

    @Autowired
    private JdpPortalMapper jdpPortalMapper;

    private final String DATA_TEXT_PREFIX = "_复制";

    @Override
    public JdpPortal selectDataById(String portalId) {
        return jdpPortalMapper.selectDataById(portalId);
    }

    @Override
    public boolean checkPortalIdUnique(JdpPortal jdpPortal) {
        if (jdpPortalMapper.selectDataById(jdpPortal.getPortalId()) == null) {
            return true;
        }
        return false;
    }

    @Override
    public int insertConfig(JdpPortal jdpPortal) {
        jdpPortal.setCreatedTime(new Date());
        jdpPortal.setUpdatedTime(new Date());
        jdpPortal.setCreatedUser("管理员");
        jdpPortalMapper.insertConfig(jdpPortal);
        return 1;
    }

    @Override
    public int updateConfig(JdpPortal jdpPortal) {
        jdpPortal.setUpdatedTime(new Date());
        jdpPortal.setUpdatedUser("管理员");
        jdpPortalMapper.updateConfig(jdpPortal);
        return 1;
    }

    @Override
    public void deleteConfigByIds(String[] portalIds) {
        jdpPortalMapper.deleteConfigByIds(portalIds);
    }

    @Override
    public List<JdpPortal> selectJdpPortalList(JdpPortal jdpPortal) {
        return jdpPortalMapper.selectJdpPortalList(jdpPortal);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int copy(JdpPortal jdpPortal) {
        jdpPortal.setPortalId(String.valueOf(System.currentTimeMillis()));
        jdpPortal.setPortalName(jdpPortal.getPortalName() + DATA_TEXT_PREFIX);
        jdpPortal.setStatus(0);
        insertConfig(jdpPortal);
        return 1;
    }
}
